package org.csu.mypetstore.web.servlets;

import org.csu.mypetstore.domain.Vertify;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//验证码
public class ValiImageServlet extends HttpServlet {
    public static String text = null;
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException {
        doGet(request, response);
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // 1.接收请求
    // 2.调用工具类，生成验证码图片
        Vertify vc = new Vertify();
    // 3.将生成的验证码图片存入response实体中
        vc.drawImage(response.getOutputStream());
    // 4.控制浏览器不要缓存验证码图片
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
    //将生成的验证码的文本内容输出到控制台
        text = vc.getCode();
        System.out.println("text=" + text);
    }
}
